package agent.vision;

import settings.Settings;
import agent.memory.MemoryA;
import environment.Environment;

import java.util.Date;

public class VisionScanAround_A {
	
	int side, cellCount;
	
	// double [] areaData = new double[ 9 ];
	// Date [] dateData = new Date[ 9 ];
	
	MemoryA brain;
	Environment map;
	
	public VisionScanAround_A( MemoryA brain, Environment map ) {
		
		this.side = Settings.side;
		this.cellCount = Settings.cellCount;
		
		this.brain = brain;
		this.map = map;
	}
	
	// method to recon the area immediately around the agent
	public void reconArea( int xLoc, int yLoc ) {
		
		Date maybe;
		
		for( int i = yLoc - 1; i < yLoc + 2; i++ ) {
			for( int j = xLoc - 1; j < xLoc + 2; j++ ) {
				
				try {
					
					// if area untraversable, sets memory value to high value
					if( map.GUI[ i ][ j ] == 2 || map.GUI[ i ][ j ] == 4 || map.GUI[ i ][ j ] == 5 || map.GUI[ i ][ j ] == 6 ) {
						
						brain.memHits[ i ][ j ] = 10000;
						brain.memDate[ i ][ j ] = new Date();
					}
					
					// if area traversable, increments memory value by 1
					else if( map.GUI[ i ][ j ] == 1 || map.GUI[ i ][ j ] == 3 ) {
						
						maybe = new Date();
						
						// only increments if last increment was more than 10 seconds ago or this is first increment
						if( ( brain.memDate[ i ][ j ] == null ) || ( maybe.getTime() / 1000 ) > ( ( brain.memDate[ i ][ j ].getTime() / 1000 ) + 10 ) ) {
							
							brain.memHits[ i ][ j ]++;
							brain.memDate[ i ][ j ] = maybe;
						}
					}
					
					// if area is the start, sets memory value to low value 
					else if( map.GUI[ i ][ j ] == 8 ) {
						
						brain.memHits[ i ][ j ] = -10000;
						brain.memDate[ i ][ j ] = new Date();
					}
					
					// if area is the goal, sets memory value to certain value and sets goal to found
					else if( map.GUI[ i ][ j ] == 7 ) {
						
						brain.goalFound = true;
						brain.memHits[ i ][ j ] = -10;
						brain.memDate[ i ][ j ] = new Date();
					}
				}
				
				catch( ArrayIndexOutOfBoundsException e ) {	
				}
			}
		}
	}
}
